import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import javax.swing.BorderFactory;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.border.LineBorder;


import tpFL1.soutenance.Soutenance;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Grille extends javax.swing.JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public JTextField champNomStagiaire;
	public JTextField champNomEntreprise;
	public JButton jButtonAjoutSoutenance;
	public JPanel jPanelPlanning;
	private JTextField champTitre;
	private JLabel jLabelTitre;
	private JButton jButtonSave;
	public JComboBox<String> jComboBoxJour;
	public JComboBox<String> jComboBoxHeure;
	public JLabel jLabelIndicHeure;
	public JLabel jLabelIndicJour;
	public JTable jTablePlanning;
	public JPanel jPanelAjoutSoutenance;
	public JButton jButtonSupprimer;
	public JLabel labelHeure;
	public JLabel labelJour;
	public JLabel labelNomEntreprise;
	public JLabel labelNomStagiaire;
	public JLabel labelAjoutSoutenance;
	public ModelePlanning tabPlanningModel;
	public GestionnairePlanning myplannig;
	//private List<Soutenance> list;

	/**
	* Auto-generated main method to display this JFrame
	*/

	
	public Grille() {
		super();
		initGUI();
	}
	
	protected void processWindowEvent(WindowEvent e) { 
	    super.processWindowEvent(e); 
	    if (e.getID() == WindowEvent.WINDOW_CLOSING) { 
	      System.exit(0); 
	    } 
	  } 
	
	private void initGUI() {
		try {
			//setDefaultCloseOperation(WindowConstants);
			
			getContentPane().setLayout(null);
			this.setTitle("Planning Soutenance");
			{
				labelAjoutSoutenance = new JLabel();
				getContentPane().add(labelAjoutSoutenance);
				labelAjoutSoutenance.setText("Ajouter soutenance");
				labelAjoutSoutenance.setBounds(12, 14, 271, 16);
				labelAjoutSoutenance.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
				labelAjoutSoutenance.setVisible(false);
			}
			{
				jPanelPlanning = new JPanel();
				getContentPane().add(jPanelPlanning);
				jPanelPlanning.setLayout(null);
				jPanelPlanning.setBounds(340, 12, 761, 252);
				jPanelPlanning.setBorder(BorderFactory
						.createTitledBorder("Planning : gestion des soutenances"));
				{
					jButtonSupprimer = new JButton();
					jPanelPlanning.add(jButtonSupprimer);
					jButtonSupprimer.setText("supprimer");
					jButtonSupprimer.setBounds(17, 213, 121, 23);
					jButtonSupprimer.setEnabled(true);
					jButtonSupprimer.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent e) {
							try {
								int[] selected = jTablePlanning.getSelectedRows();
								for(int i= selected.length-1;i>=0;i--){
									Soutenance so = tabPlanningModel.removeToAllSouternance(selected[i]);
									GestionnairePlanning.delSoutenance(so);
								}
							} catch (Exception e1) {
								e1.printStackTrace();
								System.exit(0);
							}
						}
					});
				}
				{
					tabPlanningModel = new ModelePlanning();

					jTablePlanning = new JTable();
					jTablePlanning.setModel(tabPlanningModel);
					jTablePlanning.setBounds(17, 30, 512, 171);
					JScrollPane scrolTablePlanning = new JScrollPane(jTablePlanning);
					scrolTablePlanning.setBounds(10, 36, 739, 172);
					jPanelPlanning.add(scrolTablePlanning);
					scrolTablePlanning.setBackground(new java.awt.Color(255,255,255));
					scrolTablePlanning.setForeground(new java.awt.Color(255,255,255));
				}
			}
			{
				jPanelAjoutSoutenance = new JPanel();
				getContentPane().add(jPanelAjoutSoutenance);
				jPanelAjoutSoutenance.setBounds(12, 40, 307, 224);
				jPanelAjoutSoutenance.setBorder(BorderFactory.createTitledBorder("Ajout Soutenance"));
				jPanelAjoutSoutenance.setLayout(null);
				{
					jButtonAjoutSoutenance = new JButton();
					jPanelAjoutSoutenance.add(jButtonAjoutSoutenance);
					jButtonAjoutSoutenance.setText("Ajouter");
					jButtonAjoutSoutenance.setBounds(78, 185, 103, 23);
					jButtonAjoutSoutenance.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent e) {
							try {
								Soutenance so = new Soutenance();
								so.setDay("j"+jComboBoxJour.getSelectedItem()+"");
								so.setHour("h"+jComboBoxHeure.getSelectedItem()+"");
								so.setNomEntreprise(champNomEntreprise.getText());
								so.setNomStagiaire(champNomStagiaire.getText());
								so.setTitle(champTitre.getText());
								int i = GestionnairePlanning.s.getListeSoutenance().getSoutenance().size()-1;
								if(i<0)i=0;
								Soutenance last = GestionnairePlanning.s.getListeSoutenance().getSoutenance().get(i);
								so.setId("s"+(Integer.parseInt(""+last.getId().charAt(1))+1)+(champNomEntreprise.getText().substring(0,1))+(champNomStagiaire.getText().substring(0,1)));
								Soutenance st = tabPlanningModel.addToAllSoutenance(so);
								GestionnairePlanning.addSoutenance(st);
							} catch (Exception e1) {
								e1.printStackTrace();
								System.exit(0);
							}
						}
					});
				}
				{
					labelJour = new JLabel();
					jPanelAjoutSoutenance.add(labelJour);
					labelJour.setText("Jour");
					labelJour.setBounds(14, 127, 46, 16);
				}
				{
					labelHeure = new JLabel();
					jPanelAjoutSoutenance.add(labelHeure);
					labelHeure.setText("Plage horaire");
					labelHeure.setBounds(141, 127, 99, 16);
				}
				{
					labelNomEntreprise = new JLabel();
					jPanelAjoutSoutenance.add(labelNomEntreprise);
					labelNomEntreprise.setText("Nom de l'entreprise");
					labelNomEntreprise.setBounds(16, 91, 122, 16);
				}
				{
					champNomEntreprise = new JTextField();
					jPanelAjoutSoutenance.add(champNomEntreprise);
					champNomEntreprise.setBounds(129, 88, 167, 23);
				}
				{
					labelNomStagiaire = new JLabel();
					jPanelAjoutSoutenance.add(labelNomStagiaire);
					labelNomStagiaire.setText("Nom du stagiaire");
					labelNomStagiaire.setBounds(17, 56, 122, 16);
				}
				{
					champNomStagiaire = new JTextField();
					jPanelAjoutSoutenance.add(champNomStagiaire);
					champNomStagiaire.setBounds(129, 53, 167, 23);
				}
				{
					jLabelIndicJour = new JLabel();
					jPanelAjoutSoutenance.add(jLabelIndicJour);
					jLabelIndicJour.setBounds(57, 153, 84, 10);
				}
				{
					jLabelIndicHeure = new JLabel();
					jPanelAjoutSoutenance.add(jLabelIndicHeure);
					jLabelIndicHeure.setBounds(204, 153, 86, 10);
				}
				{
					ComboBoxModel<String> jComboBoxHeureModel = 
							new DefaultComboBoxModel<String>(
									new String[] { "1", "2", "3", "4", "5", "6", "7", "8" });
					jComboBoxHeure = new JComboBox<String>();
					jPanelAjoutSoutenance.add(jComboBoxHeure);
					jComboBoxHeure.setModel(jComboBoxHeureModel);
					jComboBoxHeure.setBounds(246, 124, 47, 23);
				}
				{
					ComboBoxModel<String> jComboBoxJourModel = 
							new DefaultComboBoxModel<String>(
									new String[] { "1", "2", "3", "4", "5"});
					jComboBoxJour = new JComboBox<String>();
					jPanelAjoutSoutenance.add(jComboBoxJour);
					jComboBoxJour.setModel(jComboBoxJourModel);
					jComboBoxJour.setBounds(57, 124, 51, 23);
				}
				{
					jLabelTitre = new JLabel();
					jPanelAjoutSoutenance.add(jLabelTitre);
					jLabelTitre.setText("Titre");
					jLabelTitre.setBounds(17, 24, 61, 16);
				}
				{
					champTitre = new JTextField();
					jPanelAjoutSoutenance.add(champTitre);
					champTitre.setBounds(90, 21, 206, 23);
				}
			}
			{
				jButtonSave = new JButton();
				getContentPane().add(jButtonSave);
				jButtonSave.setText("Enregister et quiter");
				jButtonSave.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						try {
							GestionnairePlanning.unmarshall();
							System.exit(0);
						} catch (Exception e1) {
							e1.printStackTrace();
							System.exit(0);
						}
					}
				});
				jButtonSave.setBounds(12, 12, 169, 23);
				jButtonSave.setForeground(new java.awt.Color(64,0,64));
			}
			pack();
			this.setSize(1143, 330);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
}
